package com.lagou.edu.controller;

import com.lagou.edu.service.IAuthCodeService;
import com.lagou.edu.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 赵虎
 * @date 2021/2/18 10:28 上午
 */
@Slf4j
@RestController
@RequestMapping("/code")
public class AuthCodeController {

    @Autowired
    private IAuthCodeService authCodeService;

    @GetMapping("/create/{email}")
    public boolean createEmailCode(@PathVariable("email") String email) {
        log.info("  createAuthCode  email:{}.  ", email);
        authCodeService.createCode(email);
        return Boolean.TRUE;
    }

    @GetMapping("/validate/{email}/{code}")
    public ResultVO validateAuthCode(@PathVariable("email") String email, @PathVariable("code") String code) {
        log.info("  validateAuthCode  email:{}. code:{}. ", email, code);
        return authCodeService.validateAuthCode(email, code);
    }
}
